#include "remindadd.h"
#include "ui_remindadd.h"
#include <QToolButton>
#include <QDebug>
#include "mycalendarwidget.h"
#include <QDate>
#include <QMessageBox>
RemindAdd::RemindAdd(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RemindAdd)
{
    ui->setupUi(this);
    showFullScreen();
    ui->foodSelect->setParent(this);
    connect(ui->btn_back,&QToolButton::clicked,[=](){
        this->close();
        //    ui->stackedWidget->setCurrentIndex(ui->stackedWidget->currentIndex()+1);
    });
    connect(ui->btn_complete,&QToolButton::clicked,[=](){
        if (haveSelected&&(ui->amount->text()!=NULL&&ui->amount->text()!="")){
            int amount = ui->amount->text().toInt();
            if (amount<=0){
                QMessageBox::critical(this, tr("存储添加错误"), tr("请输入正确的数量，且保证数量>0"));
            }
            else{
                sql.remindAdd(this->selected.create_user,this->selected.create_id,amount,ui->dateEdit->date());
                qDebug()<<"成功添加";
                emit completed();
                this->close();
            }
        }

        // sql更新
        emit completed();
    });
    connect(ui->foodSelect,&FoodSelect::selected,this,[=](Food food){
        this->selected = food;
        this->haveSelected = true;
        ui->label_name->setText("食物:"+food.name);
    });
    ui->dateEdit->setCalendarPopup(true);
    ui->dateEdit->setCalendarWidget(new MyCalendarWidget);
    ui->dateEdit->setDate(QDate::currentDate());
    QToolButton *prevBtn = ui->dateEdit->findChild<QToolButton*>(QLatin1String("qt_calendar_prevmonth"));
    QToolButton *bextBtn = ui->dateEdit->findChild<QToolButton*>(QLatin1String("qt_calendar_nextmonth"));
    prevBtn->setFixedSize(50,50);
    bextBtn->setFixedSize(50,50);
    prevBtn->setIcon(QIcon(":/img/res/img/forward_left.png"));
    prevBtn->setIconSize(QSize(50,50));
    bextBtn->setIcon(QIcon(":/img/res/img/forward_right.png"));
    bextBtn->setIconSize(QSize(50,50));
}

RemindAdd::~RemindAdd()
{
    delete ui;
}
